package com.jk.common.utils;

import org.mindrot.jbcrypt.BCrypt;

public class PasswordUtil {

    /**
     * 加密密码
     */
    public static String hashPassword(String plainTextPassword) {
        return BCrypt.hashpw(plainTextPassword, BCrypt.gensalt());
    }

    /**
     * 验证密码
     */
    public static boolean checkPassword(String plainTextPassword, String hashedPassword) {
        return BCrypt.checkpw(plainTextPassword, hashedPassword);
    }

    public static void main(String[] args) {
        String password = "123456";

        // 加密
        String hashedPassword = hashPassword(password);
        System.out.println("Hashed Password: " + hashedPassword);

        // 验证
        boolean isMatch = checkPassword(password, hashedPassword);
        System.out.println("Password Match: " + isMatch);
    }
}